/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isip.edgeDetection;

import com.isip.transformation.difference.MatrixTransformation;

/**
 *
 * @author Fauzan
 */
public class FreiChenEdgeDetection implements EdgeDetection {
    
    
    
    @Override
    public int[][] detect(int[][] matrixImage) {
        float[] matrixConv1 = {1,0,-1,
                                (float)Math.sqrt(2),0,-(float)Math.sqrt(2),
                                1,0,-1};
        float[] matrixConv2 = {1,(float)Math.sqrt(2),1,
                                0,0,0,
                                -1,-(float)Math.sqrt(2),-1};
        int[][] tempImage1,tempImage2;
        MatrixTransformation t1 = new MatrixTransformation();
        t1.setMatrixTransformation(matrixConv1);
        tempImage1 = t1.doTransform(matrixImage);
        t1.setMatrixTransformation(matrixConv2);
        tempImage2 = t1.doTransform(matrixImage);
        
        return sum(tempImage1, tempImage2);
    }
    
    private int[][] sum(int[][] matrix1, int[][] matrix2) {
        int[][] temp = new int[matrix1.length][matrix1[0].length];
        for(int i=0; i < matrix1.length; i ++) {
            for(int j=0; j < matrix1[i].length;j++) {
                temp[i][j] = (int)Math.sqrt(matrix1[i][j]*matrix1[i][j] + matrix2[i][j]*matrix2[i][j]);
            }
        }
        return temp;
    }
    
}
